package com.csx.governance.traffic.core.interceptor.inbound;

import com.csx.governance.traffic.core.RequestAfterCompletionCleaner;
import com.csx.governance.traffic.core.context.TrafficRequest;
import com.csx.governance.traffic.core.context.TrafficResponse;

import java.util.List;

/**
 * 用于请求完成后的资源释放
 * @author cuisongxu
 * @date 2023/3/18 13:11
 */
public class RequestAfterCompletionInboundHandlerInterceptor extends TrafficAbstractInboundHandlerInterceptor {

    private final List<RequestAfterCompletionCleaner> requestAfterCompletionCleaners;

    public RequestAfterCompletionInboundHandlerInterceptor(List<RequestAfterCompletionCleaner> requestAfterCompletionCleaners) {
        this.requestAfterCompletionCleaners = requestAfterCompletionCleaners;
    }

    @Override
    public int getOrder() {
        return 10;
    }

    @Override
    public void afterCompletion(TrafficRequest request, TrafficResponse response, Throwable ex) {
        requestAfterCompletionCleaners.forEach(RequestAfterCompletionCleaner::clean);
    }
}
